﻿using System.Diagnostics;

namespace PrimeNumber
{
    internal class Program
    {
        /// <summary>
        /// 输出质数
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {

            //定义计时
            Stopwatch stopwatch = new Stopwatch();
            //输入一个数字
            Console.Write("请输入一个数input：");
            int input = int.Parse(Console.ReadLine());
            //开始计时
            stopwatch.Start();
            //从大数方向逐渐寻找质数
            int i = 2;
            for (; input > 1; input--)
            {
                for (i = 2; i <= input; i++)
                {
                    if (input % i == 0)
                        break;
                }
                if (input == i)
                {
                    Console.WriteLine($"最大的质数为{i}");
                    break;
                }
            }
            //计时结束
            stopwatch.Stop();
            //输出运行时间
            TimeSpan ts = stopwatch.Elapsed;
            double time = ts.TotalMilliseconds;
            Console.WriteLine($"运行时间为{time}毫秒");

        }
    }
}